/*
 * @Author: Otway
 * @Date: 2019-01-09 11:16:08
 * @LastEditors: Otway
 * @LastEditTime: 2019-08-30 18:50:09
 * @copyright: h-visions
 */
import React, { PureComponent } from 'react';
import {
    Row,
    Col,
    Form,
    Input,
    Select,
    Radio,
    InputNumber,
    Checkbox
} from 'antd';
const FormItem = Form.Item;
const { Option } = Select
const CheckboxGroup = Checkbox.Group;
const formItemLayout = {
    // 抽屉里面Form。二列的布局比例
    labelCol: {
        span: 6
    },
    wrapperCol: {
        span: 18
    }
};
class AddFrom extends PureComponent {
    state = {
        types: null
    }
    // 判断选中显示隐藏
    selects = (value) => {
        console.log('当前类型选中', value);
        this.setState({
            types: this.state.types = value,
        })
    }
    render() {
        const {
            formData,
            one,
            form: { getFieldDecorator },
        } = this.props;
        return (
            <Form >
                <Row>
                    <Col span={24}>
                        <FormItem {...formItemLayout} label={'检验标准编码:'}>
                            {getFieldDecorator('checkItemCode', {
                                initialValue: one ? formData.checkItemCode : '',
                                rules: [
                                    {
                                        required: true,
                                        message: '检验标准代码为空'
                                    }
                                ]
                            })(<Input placeholder='输入检验项目编码' />)}
                        </FormItem>
                    </Col>
                    <Col span={24}>
                        <FormItem {...formItemLayout} label={'检验标准名称:'}>
                            {getFieldDecorator('checkItemName', {
                                initialValue: one ? formData.checkItemName : '',
                                rules: [
                                    {
                                        required: true,
                                        message: '检验标准名称为空'
                                    }
                                ]
                            })(<Input placeholder='输入检验项目名称' />)}
                        </FormItem>
                    </Col>
                    <Col span={24}>
                        <FormItem {...formItemLayout} label={'所属表单:'}>
                            {getFieldDecorator('formProperties', {
                                initialValue: one ? formData.formProperties : '',
                                rules: [
                                    {
                                        required: true,
                                        message: '所属表单为空'
                                    }
                                ]
                            })(<Input placeholder='输入备注' />)}
                        </FormItem>
                    </Col>
                    <Col span={24}>
                        <FormItem {...formItemLayout} label={'备注:'}>
                            {getFieldDecorator('remark', {
                                initialValue: one ? formData.remark : '',
                                rules: [
                                    {
                                        required: false,
                                        message: ''
                                    }
                                ]
                            })(<Input placeholder='输入备注' />)}
                        </FormItem>
                    </Col>
                    <Col span={24}>
                        <FormItem {...formItemLayout} label={'类别一:'}>
                            {getFieldDecorator('checkTypeFirst', {
                                initialValue: one ? formData.checkTypeFirst : '',
                                rules: [
                                    {
                                        required: true,
                                        message: '类别一为空'
                                    }
                                ]
                            })(<Select allowClear={true}>
                                <Option value='类别1'>类别1</Option>
                                <Option value='类别2'>类别2</Option>
                            </Select>)}
                        </FormItem>
                    </Col>
                    <Col span={24}>
                        <FormItem {...formItemLayout} label={'类别二:'}>
                            {getFieldDecorator('checkTypeSecond', {
                                initialValue: one ? formData.checkTypeSecond : '',
                                rules: [
                                    {
                                        required: true,
                                        message: '类别二为空'
                                    }
                                ]
                            })(<Select allowClear={true}>
                                <Option value='类别1'>类别1</Option>
                                <Option value='类别2'>类别2</Option>
                            </Select>)}
                        </FormItem>
                    </Col>
                    <Col span={24}>
                        <FormItem {...formItemLayout} label={'检验项目属性:'}>
                            {getFieldDecorator('checkItemProperty', {
                                initialValue: one ? formData.checkItemProperty : '',
                                rules: [
                                    {
                                        required: true,
                                        message: '检验项目属性为空'
                                    }
                                ]
                            })(<Select allowClear={true} onChange={(value) => { this.selects(value) }}>
                                <Option value={1} key={1}>范围</Option>
                                <Option value={2} key={2}>文本</Option>
                                <Option value={3} key={3}>唯一值</Option>
                                <Option value={4} key={4}>复选</Option>
                            </Select>)}
                        </FormItem>
                    </Col>
                    {
                        this.state.types === 1 || (one ? formData.checkItemProperty : null) === 1 ? <Col span={24}>
                            <FormItem {...formItemLayout} label={'是否包含最大值:'}>
                                {getFieldDecorator('containMax', {
                                    initialValue: one ? formData.containMax : '',
                                    rules: [
                                        {
                                            required: true,
                                            message: '是否包含最大值选择项空'
                                        }
                                    ]
                                })(
                                    <Select allowClear={true}>
                                        <Option value={1}>包含</Option>
                                        <Option value={0}>不包含</Option>
                                    </Select>
                                )}
                            </FormItem>
                            <FormItem {...formItemLayout} label={'是否包含最小值:'}>
                                {getFieldDecorator('containMin', {
                                    initialValue: one ? formData.containMin : '',
                                    rules: [
                                        {
                                            required: true,
                                            message: '是否包含最小值选择项空'
                                        }
                                    ]
                                })(
                                    <Select allowClear={true}>
                                        <Option value={1}>包含</Option>
                                        <Option value={0}>不包含</Option>
                                    </Select>
                                )}
                            </FormItem>
                            <FormItem {...formItemLayout} label={'最小值:'}>
                                {getFieldDecorator('checkStandardMin', {
                                    initialValue: one ? formData.checkStandardMin : '',
                                    rules: [
                                        {
                                            required: true,
                                            message: '检验标准为空'
                                        }
                                    ]
                                })(<InputNumber />)}
                            </FormItem>
                            <FormItem {...formItemLayout} label={'最大值:'}>
                                {getFieldDecorator('checkStandardMax', {
                                    initialValue: one ? formData.checkStandardMax : '',
                                    rules: [
                                        {
                                            required: true,
                                            message: '检验标准为空'
                                        }
                                    ]
                                })(<InputNumber />)}
                            </FormItem>
                            <FormItem {...formItemLayout} label={'单位:'}>
                                {getFieldDecorator('unit', {
                                    initialValue: one ? formData.unit : '',
                                    rules: [
                                        {
                                            required: true,
                                            message: ''
                                        }
                                    ]
                                })(<Input placeholder='请输入单位' style={{ width: '150px' }} />)}
                            </FormItem>
                        </Col> : ''
                    }
                    {this.state.types === 2 || (one ? formData.checkItemProperty : null) === 2 ? <Col span={24}>
                        <FormItem {...formItemLayout} label={'文本:'}>
                            {getFieldDecorator('checkStandardText', {
                                initialValue: one ? formData.checkStandardText : '',
                                rules: [
                                    {
                                        required: true,
                                        message: ''
                                    }
                                ]
                            })(
                                <Input placeholder='输入检验标准' />
                            )}
                        </FormItem>
                    </Col> : ''}
                    {this.state.types === 3 || (one ? formData.checkItemProperty : null) === 3 ? <Col span={24}>
                        <FormItem {...formItemLayout} label={'唯一值'}>
                            {getFieldDecorator('checkStandardOption1', {
                                initialValue: one ? formData.checkStandardOption1 : '',
                                valuePropName: 'checkStandardOption1',
                                rules: [
                                    {
                                        required: true,
                                        message: '请选择'
                                    }
                                ]
                            })(
                                <Radio.Group defaultValue={(one ? formData.checkStandardOption1 : '')}>
                                    <Radio value='true'>有</Radio>
                                    <Radio value='false'>无</Radio>
                                </Radio.Group>
                            )}
                        </FormItem>
                    </Col> : ''}
                    {this.state.types === 4 || (one ? formData.checkItemProperty : null) === 4 ? <Col span={24}>
                        <FormItem {...formItemLayout} label={'复选1:'}>
                            {getFieldDecorator('checkStandardOption2', {
                                initialValue: formData.checkStandardOption2 || '',
                                valuePropName: 'checkStandardOption2',
                                rules: [
                                    {
                                        required: true,
                                        message: '全选才合格'
                                    }
                                ]
                            })(
                                <Checkbox></Checkbox>
                            )}
                        </FormItem>
                        <FormItem {...formItemLayout} label={'复选2:'}>
                            {getFieldDecorator('checkStandardOption3', {
                                initialValue: formData.checkStandardOption3 || '',
                                valuePropName: 'checkStandardOption3',
                                rules: [
                                    {
                                        required: true,
                                        message: '全选才合格'
                                    }
                                ]
                            })(
                                <Checkbox></Checkbox>
                            )}
                        </FormItem>
                        <FormItem {...formItemLayout} label={'复选3:'}>
                            {getFieldDecorator('checkStandardOption4', {
                                initialValue: formData.checkStandardOption4 || '',
                                valuePropName: 'checkStandardOption4',
                                rules: [
                                    {
                                        required: true,
                                        message: '全选才合格'
                                    }
                                ]
                            })(
                                <Checkbox></Checkbox>
                            )}
                        </FormItem>
                        <FormItem {...formItemLayout} label={'复选4:'}>
                            {getFieldDecorator('checkStandardOption5', {
                                initialValue: formData.checkStandardOption5 || '',
                                valuePropName: 'checkStandardOption5',
                                rules: [
                                    {
                                        required: true,
                                        message: '全选才合格'
                                    }
                                ]
                            })(
                                <Checkbox></Checkbox>
                            )}
                        </FormItem>
                    </Col> : ''}
                    <Col span={24}>
                        <FormItem {...formItemLayout} label={'优先级:'}>
                            {getFieldDecorator('ecnCode10', {
                                initialValue: one ? formData.ecnCode10 : '',
                                rules: [
                                    {
                                        required: false,
                                        message: ''
                                    }
                                ]
                            })(<InputNumber />)}
                        </FormItem>
                    </Col>
                </Row>
            </Form>
        );
    }
}

export default Form.create()(AddFrom);
